import _ from "lodash";
import { mapGetters, mapActions } from "vuex";
import template from "./gameBoxDlgTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  props: ["showGameBox", "gameDlgData"],
  beforeCreate() {},
  data() {
    return {
      showModal: false,
      moneyList: [10, 100, 500, 1000, 5000, "全部"],
      checkedIndex: -1,
      loading: false,
      isUser: JSON.parse(localStorage.getItem("isUser")),
      token: localStorage.getItem("token"),
      data: [],
      showGameDlg: false,
      rechargeMoney: null,
      loadBtn1: false,
      showLoad: false,
    };
  },
  created() {},
  mounted() {},
  computed: {
    ...mapGetters(["accountData"]),
  },
  methods: {
    ...mapActions(["SET_ACCOUNT_DATA"]),
    sxGameMoney() {
      this.SET_ACCOUNT_DATA({
        Obj: {},
      });
      this.showLoad = true;
      setTimeout(() => {
        this.showLoad = false;
      }, 500);
    },
    tranMoeny() {
      let vm = this;
      if (vm.rechargeMoney == null || isNaN(vm.rechargeMoney)) {
        this.$vux.toast.text("请输入正确的金额", "bottom");
        return false;
      }
      vm.loadBtn1 = true;
      let dataMess = {
        token: localStorage.getItem("token"),
        money: this.rechargeMoney,
        type: 1,
        game_plat_id: this.gameDlgData.game_plat_id,
      };
      vm.$http
        .post(this.urlRequest + "?m=api&c=game&a=transfer", dataMess)
        .then((res) => {
          vm.loadBtn1 = false;
          if (res.status == 0) {
            this.SET_ACCOUNT_DATA({
              Obj: {},
            });
            this.$vux.toast.text(res.ret_msg, "bottom");
            vm.$http
              .post(
                this.urlRequest + "?m=api&c=game&a=getGamePlatForAmtLimit",
                dataMess
              )
              .then((res) => {
                if (res.status == 0) {
                  this.cash = res.data.balance_usable;
                } else {
                  this.$vux.toast.text(res.ret_msg, "bottom");
                }
              });
          } else {
            this.$vux.toast.text(res.ret_msg, "bottom");
          }
        });
    },

    changeMoney(index) {
      this.checkedIndex = index;
      var checkedMoney = this.moneyList[index];
      if (checkedMoney == "全部") {
        this.rechargeMoney = this.accountData.money_usable;
      } else {
        this.rechargeMoney = checkedMoney;
      }
    },
    closeDlg() {
      this.$emit("changeGameDlg", false);
    },
    goGame(plat_flag) {
      this.$http
        .post(this.urlRequest + "?m=api&c=game&a=getGameUrl", {
          token: localStorage.getItem("token"),
          plat_flag: plat_flag,
        })
        .then((res) => {
          if (res.status == 0) {
            window.open(res.data.gameUrl);
          } else {
            this.$vux.toast.text(res.ret_msg, "bottom");
          }
        });
    },
  },
  watch: {
    showGameBox: function (newVal) {
      this.showModal = newVal;
    },
    accountData: {
      handler(data) {
        if (this.showModal) {
          this.$emit(
            "showGameFun",
            this.gameDlgData.game_flag,
            this.gameDlgData.game_name,
            this.gameDlgData.game_plat_id
          );
        }
      },
      deep: true,
    },
  },
  beforeDestroy() {},
};

// WEBPACK FOOTER //
// ./src/components/common/gameBoxDlg.vue
